<?php
/*
 * @Author: your name
 * @Date: 2019-10-22 16:53:17
 * @LastEditTime: 2020-12-15 17:39:29
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /ahsmp_3/application/common/service/HostLearnConfig.php
 */

namespace app\common\service\module_manage\netfilter;

use think\Db;

class HostLearnConfig
{
    /**
     * @name: 删除
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-24 11:26:09
     */
    public function del ($host_id_a)
    {
        Db::name('HostLearnConfig')->whereIn('host_id', $host_id_a)->delete();
    }

    /**
     * @name: 修改学习配置
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-31 10:38:46
     */
    public function modifyStudyConfig ($host_id, $data)
    {
        $time = time();
        $data['stime'] = $time;
        $data['etime'] = $time + $data['keep_time'];
        Db::name('HostLearnConfig')->whereIn('host_id', $host_id)->update($data);
    }

    /**
     * @name: 查找单个
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-31 10:55:03
     */
    public function findOne ($host_id)
    {
        $return = Db::name('HostLearnConfig')->where('host_id', $host_id)->find();

        return $return;
    }

    /**
     * @name: 开启学习
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-31 11:14:19
     */
    public function learnOn ($host_id,$param = [])
    {
        $time = time();
        $data['stime'] = $time;
        $data['etime'] =  Db::raw('keep_time + ' . $time);
        $data['learn_status'] = 1;

        //回调状态改为0
        $data['callback_status'] = 0;
        $data = array_merge($data,$param);
        Db::name('HostLearnConfig')->whereIn('host_id', $host_id)->update($data);
    }

    /**
     * @name: 关闭学习
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-31 11:14:19
     */
    public function learnOff ($host_id)
    {
        
        $data['etime'] =  time();
        $data['learn_status'] = 0;
        Db::name('HostLearnConfig')->whereIn('host_id', $host_id)->update($data);
    }

    /**
     * @name: netfilter 日志状态
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-24 13:38:34
     */
    public function netfilterLog ($host_id, $status)
    {
        Db::name('HostLearnConfig')->whereIn('host_id', $host_id)->update(['log_status' => $status]);
    }
    /**
     * @name: 初始化
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-31 14:34:37
     */
    public function initialization ($host_id)
    {
        Db::name('HostLearnConfig')->whereIn('host_id', $host_id)->update(['init' => 1]);
    }

    /**
     * @name: 防火墙修改
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-31 14:55:24
     */
    public function firewallConfigModify ($host_id, $firewall)
    {
        Db::name('HostLearnConfig')->whereIn('host_id', $host_id)->update(['firewall' => $firewall]);
    }

    /**
     * @name: 自动开始学习
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-04-27 10:32:40
     */
    public function autoStartLearn ($host_id_a)
    {
        Db::name('HostLearnConfig')->whereIn('host_id', $host_id_a)->where('etime', '>', time())->update(['learn_status' => 1]);
    }

    /**
     * @name: 修改日志状态
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-11-06 17:35:27
     */
    public function modifyLogStatus($host_id, $status)
    {
        $res = Db::name('HostLearnConfig')->where('host_id', $host_id)->update(['log_status' => $status]);
        return $res;
    }

    /**
     * @name: 查询列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-01-06 11:45:54
     */
    public function selectByHostId($host_id_a, $field = '*')
    {
        $return = Db::name('HostLearnConfig')->field($field) ->whereIn('host_id', $host_id_a)->select();

        return $return;
    }

    /**
     * @name: 清除提醒
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-01-08 16:30:45
     */
    public function clearReming ($host_id)
    {
        Db::name('HostLearnConfig')->whereIn('host_id', $host_id)->update(['virtual_rule_hit_remind' => 0]);
    }
}